{include file="public/toper" /}
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">运营中心</a>
        <a href="">游戏奖品管理</a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
            <input type="text" name="sreach" value=""  style="width:250px;" id="key"   placeholder="名称/库存/中奖率/描述" autocomplete="off" class="layui-input">
            <div class="layui-input-inline">
                <select name="type" id="type">
                    <option value=".">全部</option>
                    <option value="0">夺宝奇兵</option>
                    <option value="1">刮刮乐</option>
                </select>
            </div>
            <button class="layui-btn" id="search"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
    <xblock class="demoTable">
        <button class="layui-btn" onclick="x_admin_show('添加奖品','{:url(\'Prize/add\')}')"><i class="layui-icon"></i>添加</button>
        <span class="layui-btn" ><a href="{:url('Prize/index2')}" style="color: #fff">游戏奖品详情</a></span>
    </xblock>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="image">
    <img src="{{d.img}}" class="thumb" thumb="{{ d.img }}"/>
</script>
<script type="text/html" id="action">
    <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('编辑秒杀商品','{:url(\'Prize/edit\')}?id={{d.prize_id}}')"><i class="layui-icon">&#xe642;</i>编辑</button>
    <button class="layui-btn-danger layui-btn layui-btn-xs del_btn" id="{{d.prize_id}}" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</button>
</script>
<script>
    layui.use(['table'], function(){
        var table = layui.table, $ = layui.jquery;
        var layer = layui.layer;
        var loading = layer.load(1, {shade: [0.1,'#fff'] });
        var tableIn = table.render({
            method: 'post',
            elem: '#test'
            ,url: "{:url('Prize/index')}"
            ,id:'test'
            ,cols: [[
                {field:'prize_id', width:80, title: '序号',align: 'center',type:'numbers'}
                ,{field:'type', width:100, title: '类型',align: 'center',templet: function(d){if(d.type==0){return '夺宝奇兵';}else{ return '刮刮乐';}}}
                ,{field:'name',width: 150,title: '名称', align: 'center'}
                ,{width: 100,title: '奖品图片', align: 'center', toolbar: '#image'}
                ,{field:'stock',width: 100,title: '库存', align: 'center'}
                ,{field:'chance',width: 100,title: '中奖率', align: 'center'}
                ,{field:'prize_type', width:200, title: '奖品类型',align: 'center',templet: function(d){if(d.prize_type==0){return '虚拟奖品自动领奖';}else if(d.prize_type==1){return '虚拟奖品手动发放';}else if(d.prize_type==3){return '谢谢参与';}else{ return '实物奖品手动发放';}}}
                ,{field: 'create_time',width: 180, align: 'center',sort:'true',title: '添加时间'}
                ,{width: 150,title: '操作', align: 'center', toolbar: '#action'}
            ]]
            ,page: true
            ,limit: 30
            ,limits:[30,60,90,120,150,180,210,240,270,300]
        });
        layer.close(loading);


        $('#search').on('click', function () {
            tableIn.reload({
                where: {key: $('#key').val(),type:$('#type').val()}
                ,page: {curr: 1 }
            });
        });

        table.on('tool(test)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('您确定要删除【'+data.name+'】吗？',{btnAlign: 'c'}, function(index){
                    var loading = layer.load(1, {shade: [0.1,'#fff'] });
                    $.post("{:url('Prize/del')}",{id:data.prize_id},function(res){
                        layer.close(loading);
                        if(res.code==200){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload(test)
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>
{include file="public/footer"/}